package com.itheima.dbservice;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.mapper.UserApiMapper;
import com.itheima.pojo.User;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService//发布到注册中心
public class UserServiceApiImpl implements UserServiceApi {
    @Autowired
    private UserApiMapper userApiMapper;


    @Override//目的:通过手机号查询id
    public User findById(String phone) {
        //创建条件查询
        LambdaQueryWrapper<User> userLambdaQueryWrapper = new LambdaQueryWrapper<>();
        //设置条件
        userLambdaQueryWrapper.eq(User::getMobile,phone);
        //根据条件查询并返回
        return userApiMapper.selectOne(userLambdaQueryWrapper);
    }

    @Override
    public Long save(User user) {
        userApiMapper.insert(user);
        return user.getId();
    }


    //获取电话号码
    @Override
    public String getPhone(Long uid) {
        User user = userApiMapper.selectById(uid);
        return user.getMobile();
    }

    //保存修改手机号
    @Override
    public void saveChangePhone(Long uid, String phone) {
        //通过id查询表
        User user = userApiMapper.selectById(uid);
        //重新设置号码
        user.setMobile(phone);
        //更新号码
        userApiMapper.updateById(user);
    }
}
